// TypeScript file

class LoadingUINew extends eui.Component
{
    private progressMk:eui.Image;
    private progressValue:eui.BitmapLabel;
    private progress:eui.Image;
    private progressMask:eui.Image;
    private runClip:egret.MovieClip;
    private initMKX:number = 378;

    public constructor()
    {
        super();
        this.skinName = "loading_new_ui";
        this.addEventListener(egret.Event.ADDED_TO_STAGE, this.addedToStage, this);
    }
    private addedToStage(evt:egret.Event):void
    {
        this.progressValue.$setText("0%");

        this.progress = new eui.Image();
        this.progress.source = "progress_png";
        this.progress.x = 404;
        this.progress.y = 726;
        this.addChild(this.progress);


        this.progressMask = new eui.Image();
        this.progressMask.source = "progress_png";
        this.progressMask.x = 404;
        this.progressMask.y = 726;
        this.addChild(this.progressMask);
        this.progressMask.width = 0;
        this.progress.mask = this.progressMask;
        this.setChildIndex(this.progressMk,this.getChildIndex(this.progress)+1);

        let data = RES.getRes("load_run_json");
        let txtr = RES.getRes("load_run_png");
        let mcFactory:egret.MovieClipDataFactory = new egret.MovieClipDataFactory( data, txtr );
        this.runClip = new egret.MovieClip( mcFactory.generateMovieClipData( "loadRun" ) );
        this.addChild(this.runClip);
        this.runClip.x = this.progressMk.x;
        this.runClip.y = 370;
        this.runClip.gotoAndPlay(1,-1)
    }

    public setProgress(current: number, total: number): void {
        var preNum = parseInt((current / total * 100).toString());
        if (preNum > 99) {
            preNum = 99;
        }
        this.progressValue.$setText(preNum+"%");
        this.progressMask.width = (1120/100)*preNum;
        this.progressMk.x = this.initMKX + this.progressMask.width - this.progressMk.width/2; 
        this.runClip.x = this.progressMk.x


    }

}